import 'package:flutter/material.dart';
import 'package:flutter_dwh5/utils/dialog.dart';

class Edit extends StatefulWidget {
  @override
  State<Edit> createState() => _EditState();
}

class _EditState extends State<Edit> {
  TextEditingController nick = TextEditingController(text: '昵称');
  TextEditingController name = TextEditingController(text: '姓名');
  int sex = 0;

  Widget buildSexWidget() {
    return StatefulBuilder(
      builder: (BuildContext context, setState) {
        return SimpleDialog(
          contentPadding: EdgeInsets.all(30),
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
          children: [
            GestureDetector(
              onTap: () {
                setState(() {
                  if (sex != 0) {
                    sex = 0;
                  }
                });
              },
              child: Row(
                children: [
                  Container(
                    width: 17,
                    height: 17,
                    child: sex == 0
                        ? Image.asset('images/my/circular.png')
                        : Image.asset('images/my/circular2.png'),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 5),
                    child: Text('男'),
                  )
                ],
              ),
            ),
            Container(
              child: Divider(
                height: 1,
              ),
              margin: EdgeInsets.symmetric(vertical: 15),
            ),
            GestureDetector(
              onTap: () {
                setState(() {
                  if (sex != 1) {
                    sex = 1;
                  }
                });
              },
              child: Row(
                children: [
                  Container(
                    width: 17,
                    height: 17,
                    child: sex == 0
                        ? Image.asset('images/my/circular2.png')
                        : Image.asset('images/my/circular.png'),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 5),
                    child: Text('女'),
                  )
                ],
              ),
            ),
          ],
        );
        ;
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('个人资料'),
      ),
      body: Container(
        color: Colors.white,
        child: Column(
          children: [
            Container(
              margin: EdgeInsets.all(15),
              decoration: BoxDecoration(
                  border: Border(
                      bottom: BorderSide(
                          color: Color.fromRGBO(225, 225, 225, 1), width: 1))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    child: Text('昵称'),
                  ),
                  Container(
                    width: 80,
                    child: TextField(
                      textAlign: TextAlign.right,
                      controller: nick,
                      style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1)),
                      decoration: InputDecoration(border: InputBorder.none),
                    ),
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 15, right: 15),
              padding: EdgeInsets.only(bottom: 8),
              decoration: BoxDecoration(
                  border: Border(
                      bottom: BorderSide(
                          color: Color.fromRGBO(225, 225, 225, 1), width: 1))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    child: Text('头像'),
                  ),
                  Container(
                    child: Row(
                      children: [
                        Container(
                          width: 35,
                          height: 35,
                          child: CircleAvatar(
                            backgroundImage: AssetImage('images/my/avatar.png'),
                          ),
                        ),
                        Container(
                          child: Icon(
                            Icons.arrow_forward_ios_sharp,
                            color: Color.fromRGBO(153, 153, 153, 1),
                            size: 18,
                          ),
                        )
                      ],
                    ),
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 15, right: 15),
              decoration: BoxDecoration(
                  border: Border(
                      bottom: BorderSide(
                          color: Color.fromRGBO(225, 225, 225, 1), width: 1))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    child: Text('姓名'),
                  ),
                  Container(
                    width: 80,
                    child: TextField(
                      textAlign: TextAlign.right,
                      controller: name,
                      style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1)),
                      decoration: InputDecoration(border: InputBorder.none),
                    ),
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 15, right: 15, top: 15),
              padding: EdgeInsets.only(bottom: 15),
              decoration: BoxDecoration(
                  border: Border(
                      bottom: BorderSide(
                          color: Color.fromRGBO(225, 225, 225, 1), width: 1))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    child: Text('出生日期'),
                  ),
                  Container(
                    child: Row(
                      children: [
                        Container(
                          child: Text(
                            '2023-5-5',
                            style: TextStyle(
                                color: Color.fromRGBO(153, 153, 153, 1)),
                          ),
                        ),
                        Container(
                          child: Icon(
                            Icons.arrow_forward_ios_sharp,
                            color: Color.fromRGBO(153, 153, 153, 1),
                            size: 18,
                          ),
                        )
                      ],
                    ),
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 15, right: 15, top: 15),
              padding: EdgeInsets.only(bottom: 15),
              child: GestureDetector(
                onTap: () {
                  DialogUtil.show(context: context, widget: buildSexWidget());
                },
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      child: Text('性别'),
                    ),
                    Container(
                      child: Row(
                        children: [
                          Container(
                            child: Text(
                              '男',
                              style: TextStyle(
                                color: Color.fromRGBO(153, 153, 153, 1),
                              ),
                            ),
                          ),
                          Container(
                            child: Icon(
                              Icons.arrow_forward_ios_sharp,
                              color: Color.fromRGBO(153, 153, 153, 1),
                              size: 18,
                            ),
                          )
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
